﻿using System;
using System.Web.UI.WebControls;
using PM.Entities;
using PM.BusinessLayer;

public partial class UserManagement_Shedule : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ddlCourse.Items.Add("1");
            ddlCourse.Items.Add("2");
            ddlCourse.Items.Add("3");
            ddlCourse.Items.Add("4");
            ddlCourse.Items.Add("5");
            ddlCourse.Items.Add("6");
        }
    }

    protected void btnAddSheduleItem_Click(object sender, EventArgs e)
    {
        Shedule shedule = new Shedule
                              {
                                  DayID = int.Parse(ddlDays.SelectedItem.Value.ToString()),
                                  GroupID = int.Parse(ddlGroup.SelectedItem.Value.ToString()),
                                  UserID = int.Parse(ddlUser.SelectedValue.ToString()),
                                  LessonNumberID = int.Parse(ddlLessonNumber.SelectedValue.ToString()),
                                  NumberAudience = int.Parse(tbAudience.Text),
                                  SubjectID = int.Parse(ddlSubject.SelectedValue.ToString()),
                                  SpecialityID = int.Parse(ddlSpecialities.SelectedValue.ToString()),
                                  Course = int.Parse(ddlCourse.SelectedValue.ToString())
                              };
        new SheduleController().InsertSheduleItem(shedule);
        Response.Redirect(Request.RawUrl);
    }

    protected void ddlGroup_SelectedIndexChanged(object sender, EventArgs e)
    {
        ddlLessonNumber.Enabled = true;
    }
    protected void ddlLessonNumber_SelectedIndexChanged(object sender, EventArgs e)
    {
        ddlUser.Enabled = true;
        btnAddSheduleItem.Enabled = true;
    }

    protected void GrvShedule_RowDeleted(object sender, GridViewDeletedEventArgs e)
    {
        grvShedule.DataBind();
        ddlDays.DataBind();
        ddlGroup.DataBind();
        ddlCourse.DataBind();
        ddlSpecialities.DataBind();
        ddlSubject.DataBind();
        ddlUser.DataBind();
        ddlLessonNumber.DataBind();
        Response.Redirect(Request.RawUrl);

    }
}
